package com.myclover.db;

import java.util.List;

import com.myclover.db.bean.Person;
import com.myclover.db.service.DBSQLService;
import com.myclover.db.service.DBService;

import android.test.AndroidTestCase;
import android.util.Log;

public class TestDB extends AndroidTestCase {

	private static final String TAG = "TestDB";

	public void testSave() {
		DBService dbs = new DBService(this.getContext());
		for (int i = 0; i < 20; i++) {
			dbs.save(new Person("myclover" + i, "male", 10 + i, 10000.50f));
		}
	}

	public void testFindById() {
		DBService dbs = new DBService(this.getContext());
		Person p = dbs.findById(6);
		Log.i(TAG, "person = " + p);
	}

	public void testUpdate() {
		DBService dbs = new DBService(this.getContext());
		Person p = dbs.findById(5);
		p.setSex("female");
		p.setName("test5");
		p.setAge(25);
		p.setAmount(8888888.55f);
		dbs.update(p);
	}

	public void testLists() {
		DBService dbs = new DBService(this.getContext());
		List<Person> list = dbs.getPerosns(15, 10);
		for (Person p : list) {
			Log.i(TAG, "person = " + p);
		}
	}

	public void testGetNum() {
		DBService dbs = new DBService(this.getContext());
		long n = dbs.getTotalCounts();
		Log.i(TAG, "total = " + n);
	}

	public void testDelete() {
		DBService dbs = new DBService(this.getContext());
		dbs.delete(18, 19, 20, 21, 22);
	}

	public void testTrans() {
		DBService dbs = new DBService(this.getContext());
		dbs.transAmount(6, 500f, 60);
	}

	public void testSQLSave() {
		DBSQLService dbs = new DBSQLService(this.getContext());
		Person p = new Person("testSave", "female", 23, 99999999.99f);
		dbs.save(p);
	}

	public void testSQLDelete() {
		DBSQLService dbs = new DBSQLService(this.getContext());
		dbs.delete(18, 19, 20, 21, 22);
	}

	public void testGetLists() {
		DBSQLService dbs = new DBSQLService(this.getContext());
		List<Person> list = dbs.getPerosns(0, 30);
		for (Person p : list) {
			Log.i(TAG, "person = " + p);
		}
	}

	public void testSQLUpdate() {
		DBSQLService dbs = new DBSQLService(this.getContext());
		Person p = dbs.findById(6);
		p.setAge(22);
		p.setName("name_6");
		dbs.update(p);
	}

	public void testGet() {
		DBSQLService dbs = new DBSQLService(this.getContext());
		Person p = dbs.findById(6);
		Log.i(TAG, "person = " + p);
	}

	public void testNums() {
		DBSQLService dbs = new DBSQLService(this.getContext());
		long num = dbs.getTotalCounts();
		Log.i(TAG, "num = " + num);
	}

	public void testSQLTrans() {
		DBSQLService dbs = new DBSQLService(this.getContext());
		dbs.transAmount(6, 2000.5f, 22);
	}

}
